The datePickerStyle
property allows you to customize the appearance and interaction of the DatePicker
view in your UI.
DatePickerStyle
ValuesThe DatePickerStyle
property accepts the following string values to define the appearance and interaction:
automatic
: The default style for date pickers.compact
: Displays the date picker components in a compact, textual format.graphical
: Displays the date picker as an interactive calendar or clock.wheel
: Displays the date picker components as columns in a scrollable wheel.field
(macOS only): Displays the components in an editable field.stepperField
(macOS only): Displays the components in an editable field with an adjoining stepper to increment or decrement the selected component.DatePickerComponents
ValuesThe displayedComponents
property specifies which components of the date are shown and editable. Accepted values are:
date
: Displays the day, month, and year based on the locale.hourAndMinute
: Displays the hour and minute components based on the locale.hourMinuteAndSecond
(watchOS only): Displays the hour, minute, and second components based on the locale.This creates a graphical date picker for selecting a date.
This creates a compact date picker for selecting the hour and minute.
This creates a date picker with a scrollable wheel for date and time selection.
DatePickerStyle
property maps directly to SwiftUI’s datePickerStyle
modifier.displayedComponents
and datePickerStyle
values are compatible with the target platform to avoid runtime errors.field
and stepperField
), ensure the app is running on macOS.With DatePickerStyle
, you can create versatile date pickers to suit your app’s design and functional requirements.